var layer;
var form;
var lay;
var submitState = 0;
layui.use([ 'layer', 'form'], function() {
	layer = layui.layer;
	form = layui.form;

	// 监听浏览器变化
	windSize();

	// 提交登录 ==========================================================================================================
	form.on('submit(formSubmit)', function(data) {
		if(submitState == 1){
			return false;
		}
		submitState = 1;
		$(".lay-submit-btn").html("正在登录...");
		$(".lay-submit-btn").addClass("btn-submint-state");
		data.field['userName'] = aesMinEncrypt(data.field['userName']);// 加密传输
		data.field['password'] = aesMinEncrypt(data.field['password']);// 加密传输
		$.post(ctxPath+'loginJudge', data.field, function(result) {
			submitState = 0;
			layer.msg(result.msg, {offset:'30%'});
			if(result.success){
				window.location.href = ctxPath+"jumpMain";
			}else{
				refreshCaptcha();
			}
			$(".lay-submit-btn").html("登&nbsp;&nbsp;录");
			$(".lay-submit-btn").removeClass("btn-submint-state");
		})
		return false;
	});





});


/**
 * --------------------------------------------------------------------------------------------------------------------
 * 刷新验证码
 */
function refreshCaptcha(){
	$(".code-img").attr("src", ctxPath+"captcha/code?time="+Math.random());
}

/**
 * --------------------------------------------------------------------------------------------------------------------
 * 监听浏览器变化（兼容窗口）
 */
$(window).resize(function(){
	windSize();
})
function windSize(){
	var w = $(document).width();
	if(w < 1100){
		$(".beg-login-box").addClass('app-form');
		if(w < 400){
			$(".beg-login-box").addClass('app-form-min');
		}else{
			$(".beg-login-box").removeClass('app-form-min');
		}
		$(".img_left").css('display', 'none');
	}else{
		$(".beg-login-box").removeClass('app-form app-form-min');
		$(".img_left").css('display', 'inline-block');
	}
}

/**
 * --------------------------------------------------------------------------------------------------------------------
 * 防止页面后退
 */
window.history.go(1);
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function() {
	history.pushState(null, null, document.URL);
});
if (window != top) {  
    top.location.href = location.href;  
}

/**
 * --------------------------------------------------------------------------------------------------------------------
 * IE版本判断
 * @returns {string|number}
 * @constructor
 */
function IEVersion() {
	var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
	var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
	var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
	var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
	if(isIE) {
		var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
		reIE.test(userAgent);
		var fIEVersion = parseFloat(RegExp["$1"]);
		if(fIEVersion == 7) {
			return 7;
		} else if(fIEVersion == 8) {
			return 8;
		} else if(fIEVersion == 9) {
			return 9;
		} else if(fIEVersion == 10) {
			return 10;
		} else {
			return 6;//IE版本<=7
		}
	} else if(isEdge) {
		return 'edge';//edge
	} else if(isIE11) {
		return 11; //IE11
	}else{
		return -1;//不是ie浏览器
	}
}
var IEV = IEVersion();
if(IEV != -1 && IEV != 'edge' && IEV < 10){
	alert("请使用IE10及以上版本浏览器操作，否则部分功能无法正常使用")
}

